package com.eastfair.saga.proxy.impl;

import com.eastfair.core.context.ContextUtil;
import com.eastfair.saga.proxy.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Slf4j
public class AccountServiceImpl implements AccountService {
    /**
     * 金额
     */
    public static Integer account = 10000;


    @Override
    public Boolean reduceBalance(Long userId, Integer amount) throws Exception {
        account = account - amount;
        log.info(ContextUtil.getProjectId()+" :::开始减扣金额：：" + amount+",余额："+ account);
        return true;
    }

    @Override
    public Boolean compensateBalance(Long userId, Integer amount) throws Exception {

        account = account + amount;
        log.info(ContextUtil.getProjectId()+" :::开始退还金额：：" + amount+",余额："+ account);
        return true;
    }
}
